#include "delge_squirrelaudio_sound.h"

void s_Audio_Sound_RegisterFunctions (HSQUIRRELVM v)
{
	SquirrelVM::CreateFunctionGlobal(s_Audio_Sound_Play,				_SC("Sound_Play"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Sound_SetVolume,			_SC("Sound_SetVolume"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Sound_GetVolume,			_SC("Sound_GetVolume"),					_SC("*"));
}

SQInteger s_Audio_Sound_Play (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Sound *pSound = ResourceManager<Sound>::GetResource(sResourceName);

	pSound->Play();

	return 0;
}

SQInteger s_Audio_Sound_SetVolume (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;
	SQFloat					fVolume;

	sq_getstring			(v, 2, &sResourceName);
	sq_getfloat				(v, 3, &fVolume);

	Sound *pSound = ResourceManager<Sound>::GetResource(sResourceName);

	pSound->SetVolume(fVolume);

	return 0;
}

SQInteger s_Audio_Sound_GetVolume (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Sound *pSound = ResourceManager<Sound>::GetResource(sResourceName);

	sq_pushfloat			(v, pSound->GetVolume());

	return 1;
}